'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var ResourceType = function (_React$Component) {
    _inherits(ResourceType, _React$Component);

    function ResourceType(props) {
        _classCallCheck(this, ResourceType);

        var _this = _possibleConstructorReturn(this, (ResourceType.__proto__ || Object.getPrototypeOf(ResourceType)).call(this, props));

        _this.page = 1;
        _this.state = {
            treeList: [],
            modalList: [],
            typelist: [],
            selectParent: {
                parent_name: '',
                parent_code: ''
            },
            inputValues: {
                type_id: '',
                parent_codes: '',
                type_name: '',
                type_code: '',
                minConut: '',
                maxConut: '',
                sortEncoding: 0,
                description: ''
            },
            customContent: {},
            customView: [],
            customPropertyIds: [],
            customPropertyPrivateIds: [],
            customContentIds: [],
            addCustomType: {
                customType: '',
                callback: function callback(ids) {}
            }
        };
        return _this;
    }

    _createClass(ResourceType, [{
        key: 'componentDidMount',
        value: function componentDidMount() {
            var _this2 = this;

            this.queryTreeList();
            var isNum = /^[0-9]+$/;
            var regCode = /^[a-zA-Z_0-9]+$/;
            this.verify = {
                type_code: function type_code(value) {
                    if (value.length < 2) {
                        return '分类编码至少得2个字符!';
                    }
                    if (!regCode.test(value)) {
                        return '分类编码只能是英文，数字，下划线组成！';
                    }
                },
                minConut: function minConut(value) {
                    if (value && !isNum.test(value)) {
                        return '最小条目必须是数字！';
                    }
                },
                maxConut: function maxConut(value) {
                    if (value && !isNum.test(value)) {
                        return '最大条目必须是数字！';
                    }
                    if (_this2.state.inputValues.minConut && value < _this2.state.inputValues.minConut) {
                        return '最大条目必须大于最小条目!';
                    }
                },
                sortEncoding: function sortEncoding(value) {
                    if (value && !isNum.test(value)) {
                        return '排序编码必须是数字！';
                    }
                }
            };
        }
    }, {
        key: 'queryTreeList',
        value: function queryTreeList() {
            var _this3 = this;

            postJson("/cms/resource/type/queryResourceTypes.x", null, function (data) {
                var treeList = _this3.refs.tree.getNodes(data.data, "-1", 'parent_code', 'type_code', 'type_name');
                var modalList = _this3.refs.treeModal.getNodes(data.data, "-1", 'parent_code', 'type_code', 'type_name');
                modalList.unshift({ name: '无' });
                console.log("modalList", modalList);
                _this3.setState({
                    typelist: data.data,
                    treeList: treeList,
                    modalList: modalList
                });
            });
        }
    }, {
        key: 'onSelected',
        value: function onSelected(data) {
            var _this4 = this;

            console.log("data", data);
            var selectParent = {
                parent_name: '',
                parent_code: ''
            };
            for (var i in this.state.typelist) {
                if (this.state.typelist[i].type_code === data.parent_code) {
                    selectParent = {
                        parent_name: this.state.typelist[i].type_name,
                        parent_code: this.state.typelist[i].type_code
                    };
                    break;
                }
            }
            this.setState({
                selectParent: selectParent,
                inputValues: {
                    type_id: data.type_id,
                    parent_codes: '',
                    type_name: data.type_name,
                    type_code: data.type_code,
                    minConut: data.minConut,
                    maxConut: data.maxConut,
                    sortEncoding: data.sortEncoding,
                    description: data.description
                }
            }, function () {
                _this4.customView(_this4.state.selectParent.parent_code, data.customProperty);
                _this4.getCustomTypeByIds('CUSTOM_TYPE', data.customContentId);
                _this4.getCustomTypeByIds('CUSTOM_PROPERTY', data.customPropertyId);
                _this4.getCustomTypeByIds('CUSTOM_PROPERTY_PRIVATE', data.customPropertyPrivateId);
            });
        }
    }, {
        key: 'customChange',
        value: function customChange(type, value) {
            this.state.customContent[type] = value;
            this.setState({});
        }
    }, {
        key: 'inputChange',
        value: function inputChange(type, value) {
            this.state.inputValues[type] = value;
            this.setState({});
        }
    }, {
        key: 'customView',
        value: function customView(parentCode, customPropertys) {
            var _this5 = this;

            if (customPropertys) customPropertys = JSON.parse(customPropertys);
            this.state.customView = [];
            for (var i in this.state.typelist) {
                if (this.state.typelist[i].type_code === parentCode && this.state.typelist[i].customPropertyId) {
                    var param = {};
                    param.isPage = false;
                    param.isAnalysisCustomContent = true;
                    param.customTypeId = this.state.typelist[i].customPropertyId;
                    postJson("/cms/resource/queryCustomTypeList.x", $.param(param), function (data) {
                        var customTypeList = data.data.list;
                        for (var _i in customTypeList) {
                            var customContents = customTypeList[_i].customContents;

                            var _loop = function _loop(j) {
                                var customContent = customContents[j];
                                if (customContent && customContent.customType === 'CMS_CUSTOM_SORT') {
                                    var option = [];
                                    var customValue = '';
                                    if (customContent.spinnerMap) {
                                        for (var key in customContent.spinnerMap) {
                                            for (var k in customPropertys) {
                                                if (customPropertys[k].customKey === customContent.customKey && customPropertys[k].customValue === key) {
                                                    customValue = customPropertys[k].customValue;
                                                    break;
                                                }
                                            }
                                            option.push(React.createElement(
                                                'option',
                                                { value: key },
                                                customContent.spinnerMap[key]
                                            ));
                                        }
                                    } else {
                                        option.push(React.createElement(
                                            'option',
                                            { value: '-1' },
                                            '\u65E0'
                                        ));
                                    }
                                    _this5.state.customContent[customContent.customKey] = {
                                        customValue: customValue,
                                        customDescribe: customContent.customDescribe
                                    };
                                    _this5.state.customView.push(React.createElement(
                                        Item,
                                        null,
                                        React.createElement(
                                            Label,
                                            null,
                                            customContent.customName
                                        ),
                                        React.createElement(
                                            Select,
                                            { onChange: function onChange(data) {
                                                    return _this5.customChange(customContent.customKey, data);
                                                },
                                                value: _this5.state.customContent[customContent.customKey].customValue },
                                            [].concat(option)
                                        )
                                    ));
                                } else if (customContent) {
                                    var value = '';
                                    for (var l in customPropertys) {
                                        if (customPropertys[l].customKey === customContent.customKey) {
                                            value = customPropertys[l].customValue;
                                            break;
                                        }
                                    }
                                    _this5.state.customContent[customContent.customKey] = {
                                        customValue: value,
                                        customDescribe: customContent.customDescribe
                                    };
                                    _this5.state.customView.push(React.createElement(
                                        Item,
                                        null,
                                        React.createElement(
                                            Label,
                                            null,
                                            customContent.customName
                                        ),
                                        React.createElement(Input, { type: 'text',
                                            block: true,
                                            value: _this5.state.customContent[customContent.customKey].customValue,
                                            ref: customContent.customKey,
                                            onChange: function onChange(value) {
                                                return _this5.customChange(customContent.customKey, value);
                                            }
                                        })
                                    ));
                                }
                            };

                            for (var j in customContents) {
                                _loop(j);
                            }
                        }
                        _this5.setState({});
                    });
                }
            }
            this.setState({});
        }
    }, {
        key: 'getCustomTypeByIds',
        value: function getCustomTypeByIds(type, customContentId) {
            var _this6 = this;

            this.state.customPropertyIds = [];
            this.state.customPropertyPrivateIds = [];
            this.state.customContentIds = [];
            if (customContentId) {
                var param = {};
                param.isPage = false;
                param.customTypeId = customContentId;
                postJson("/cms/resource/queryCustomTypeList.x", $.param(param), function (data) {
                    if (type === 'CUSTOM_PROPERTY') {
                        _this6.state.customPropertyIds = data.data.list;
                    } else if (type === 'CUSTOM_PROPERTY_PRIVATE') {
                        _this6.state.customPropertyPrivateIds = data.data.list;
                    } else {
                        _this6.state.customContentIds = data.data.list;
                    }
                    _this6.setState({});
                });
            } else {
                this.setState({});
            }
        }
    }, {
        key: 'addCustomType',
        value: function addCustomType(customType, _callback) {
            var _this7 = this;

            this.setState({
                addCustomType: {
                    customType: customType,
                    callback: function callback(ids) {
                        return _callback(ids);
                    }
                }
            }, function () {
                _this7.refs.CustomTypeListModal.show();
            });
        }
    }, {
        key: 'render',
        value: function render() {
            var _this8 = this;

            return React.createElement(
                Frame,
                { header: '\u7F16\u8F91\u8D44\u6E90\u7C7B\u578B', headerBtns: React.createElement(
                        SecurityCheck,
                        { roles: 'admin' },
                        React.createElement(
                            HeaderBtn,
                            { onClick: function onClick() {
                                    return _this8.addAppConfigType();
                                } },
                            '\u6E05\u7A7A\u7F13\u5B58'
                        )
                    ) },
                React.createElement(
                    'div',
                    { style: { marginTop: '15px', width: '20%', border: '1px solid #ddd', display: 'inline-block' } },
                    React.createElement(Tree, { ref: 'tree', nodes: this.state.treeList, errorStr: '\u65E0\u4E0A\u7EA7\u8282\u70B9',
                        onItemSelect: function onItemSelect(data) {
                            return _this8.onSelected(data);
                        } })
                ),
                React.createElement(
                    'div',
                    { style: { display: 'inline-block', width: '75%', verticalAlign: 'top', paddingLeft: '20px' } },
                    React.createElement(
                        Form,
                        { id: 'form', type: 'pane' },
                        React.createElement(Input, { type: 'hidden', value: this.state.inputValues.type_id }),
                        React.createElement(Input, { type: 'hidden', value: this.state.inputValues.parent_codes }),
                        React.createElement(
                            Item,
                            null,
                            React.createElement(
                                Label,
                                null,
                                '\u4E0A\u7EA7\u5206\u7C7B'
                            ),
                            React.createElement(Input, { type: 'text',
                                readonly: 'readonly',
                                ref: 'parent_name',
                                value: this.state.selectParent.parent_name,
                                placeholder: '\u8BF7\u9009\u62E9\u4E0A\u7EA7\u5206\u7C7B',
                                onClick: function onClick() {
                                    return _this8.refs.treeModal.show({ typeData: _this8.refs.parent_name.refs.input });
                                }
                            })
                        ),
                        React.createElement(
                            Item,
                            null,
                            React.createElement(
                                Label,
                                null,
                                '\u5206\u7C7B\u540D\u79F0'
                            ),
                            React.createElement(Input, { type: 'text',
                                'lay-verify': 'type_name',
                                value: this.state.inputValues.type_name,
                                placeholder: '\u8BF7\u8F93\u5165\u5206\u7C7B\u540D\u79F0',
                                onChange: function onChange(value) {
                                    return _this8.inputChange('type_name', value);
                                }
                            })
                        ),
                        React.createElement(
                            Item,
                            null,
                            React.createElement(
                                Label,
                                null,
                                '\u5206\u7C7B\u7F16\u7801'
                            ),
                            React.createElement(Input, { type: 'text',
                                ref: 'type_code',
                                'lay-verify': 'type_code',
                                value: this.state.inputValues.type_code,
                                placeholder: '\u8BF7\u8F93\u5165\u82F1\u6587\u5206\u7C7B\u7F16\u7801',
                                onChange: function onChange(value) {
                                    return _this8.inputChange('type_code', value);
                                }
                            })
                        ),
                        React.createElement(
                            Item,
                            null,
                            React.createElement(
                                Label,
                                null,
                                '\u6761\u76EE\u8303\u56F4'
                            ),
                            React.createElement(Input, { type: 'text',
                                ref: 'minConut',
                                'lay-verify': 'minConut',
                                value: this.state.inputValues.minConut,
                                placeholder: '\u6700\u5C0F\u6761\u76EE',
                                onChange: function onChange(value) {
                                    return _this8.inputChange('minConut', value);
                                }
                            }),
                            React.createElement(Input, { type: 'text',
                                ref: 'maxConut',
                                'lay-verify': 'maxConut',
                                value: this.state.inputValues.maxConut,
                                placeholder: '\u6700\u5927\u6761\u76EE',
                                onChange: function onChange(value) {
                                    return _this8.inputChange('maxConut', value);
                                }
                            })
                        ),
                        React.createElement(
                            Item,
                            null,
                            React.createElement(
                                Label,
                                null,
                                '\u6392\u5E8F\u7F16\u53F7'
                            ),
                            React.createElement(Input, { type: 'text',
                                ref: 'sortEncoding',
                                'lay-verify': 'sortEncoding',
                                value: this.state.inputValues.sortEncoding,
                                placeholder: '\u8BF7\u8F93\u5165\u6392\u5E8F\u7F16\u53F7',
                                onChange: function onChange(value) {
                                    return _this8.inputChange('sortEncoding', value);
                                }
                            })
                        ),
                        React.createElement(
                            Item,
                            null,
                            React.createElement(
                                Label,
                                null,
                                '\u63CF\u8FF0'
                            ),
                            React.createElement(Input, { type: 'text',
                                block: true,
                                ref: 'description',
                                value: this.state.inputValues.description,
                                placeholder: '\u8BF7\u8F93\u5165\u63CF\u8FF0',
                                onChange: function onChange(value) {
                                    return _this8.inputChange('description', value);
                                }
                            })
                        ),
                        [].concat(_toConsumableArray(this.state.customView)),
                        React.createElement(
                            Item,
                            { className: 'layui-form-text' },
                            React.createElement(
                                Label,
                                null,
                                '\u6DFB\u52A0\u5B50\u8282\u70B9\u81EA\u5B9A\u4E49\u5C5E\u6027\xA0\xA0\u3010\u6DFB\u52A0\u5B50\u8282\u70B9\u81EA\u5B9A\u4E49\u5C5E\u6027\u540E\uFF0C\u6240\u6709\u5B50\u8282\u70B9\u5C06\u62E5\u6709\u8BE5\u5C5E\u6027\u3011'
                            ),
                            React.createElement(
                                Tab,
                                { titles: ['共有属性', '私有属性'], ids: ['0', '1'], type: 'brief' },
                                React.createElement(
                                    TabItem,
                                    { show: 'true' },
                                    React.createElement(
                                        'div',
                                        { style: {
                                                background: '#FFFFFF',
                                                paddingTop: '10px',
                                                paddingLeft: '10px',
                                                paddingRight: '10px'
                                            } },
                                        React.createElement(
                                            Button,
                                            { size: 'xs',
                                                onClick: function onClick() {
                                                    return _this8.addCustomType('CUSTOM_PROPERTY', function (ids) {
                                                        _this8.setState({
                                                            customPropertyIds: ids
                                                        });
                                                    });
                                                } },
                                            '\u6DFB\u52A0\u5171\u6709\u5C5E\u6027'
                                        ),
                                        React.createElement('hr', { style: { background: '#00acd6' } }),
                                        React.createElement(
                                            'div',
                                            { id: 'customPropertyPerms',
                                                className: 'layui-input-block',
                                                style: { padding: '10px' } },
                                            this.state.customPropertyIds.map(function (array, index) {
                                                return React.createElement(
                                                    'div',
                                                    null,
                                                    React.createElement(
                                                        'div',
                                                        { style: { float: 'left', marginRight: '20px' } },
                                                        React.createElement(
                                                            'div',
                                                            null,
                                                            '\u81EA\u5B9A\u4E49\u5206\u7C7B\u540D\u79F0\uFF1A ',
                                                            array.custom_type_name
                                                        )
                                                    ),
                                                    React.createElement(
                                                        Button,
                                                        { size: 'xs', btnType: 'danger',
                                                            onClick: function onClick() {
                                                                _this8.state.customPropertyIds.splice(index, 1);
                                                                _this8.setState({});
                                                            } },
                                                        '\u5220\u9664'
                                                    ),
                                                    React.createElement(
                                                        Button,
                                                        { size: 'xs',
                                                            onClick: function onClick() {
                                                                return _this8.edit(array);
                                                            } },
                                                        '\u67E5\u770B'
                                                    ),
                                                    React.createElement('hr', null)
                                                );
                                            })
                                        )
                                    )
                                ),
                                React.createElement(
                                    TabItem,
                                    null,
                                    React.createElement(
                                        'div',
                                        {
                                            style: {
                                                background: '#FFFFFF',
                                                paddingTop: '10px',
                                                paddingLeft: '10px',
                                                paddingRight: '10px'
                                            } },
                                        React.createElement(
                                            Button,
                                            { size: 'xs',
                                                onClick: function onClick() {
                                                    return _this8.addCustomType('CUSTOM_PROPERTY_PRIVATE', function (ids) {
                                                        _this8.setState({
                                                            customPropertyPrivateIds: ids
                                                        });
                                                    });
                                                } },
                                            '\u6DFB\u52A0\u79C1\u6709\u5C5E\u6027'
                                        ),
                                        React.createElement('hr', { style: { background: '#00acd6' } }),
                                        React.createElement(
                                            'div',
                                            { id: 'customPropertyPrivatePerms', className: 'layui-input-block',
                                                style: { padding: '10px' } },
                                            this.state.customPropertyPrivateIds.map(function (array, index) {
                                                console.log("index", index);
                                                return React.createElement(
                                                    'div',
                                                    null,
                                                    React.createElement(
                                                        'div',
                                                        { style: { float: 'left', marginRight: '20px' } },
                                                        React.createElement(
                                                            'div',
                                                            null,
                                                            '\u81EA\u5B9A\u4E49\u5206\u7C7B\u540D\u79F0\uFF1A ',
                                                            array.custom_type_name
                                                        )
                                                    ),
                                                    React.createElement(
                                                        Button,
                                                        { size: 'xs', btnType: 'danger',

                                                            onClick: function onClick() {
                                                                _this8.state.customPropertyPrivateIds.splice(index, 1);
                                                                _this8.setState({});
                                                            } },
                                                        '\u5220\u9664'
                                                    ),
                                                    React.createElement(
                                                        Button,
                                                        { size: 'xs',
                                                            onClick: function onClick() {
                                                                return _this8.edit(array);
                                                            } },
                                                        '\u67E5\u770B'
                                                    ),
                                                    React.createElement('hr', null)
                                                );
                                            })
                                        )
                                    )
                                )
                            )
                        ),
                        React.createElement(
                            Item,
                            { className: 'layui-form-text' },
                            React.createElement(
                                Label,
                                null,
                                '\u9009\u62E9\u81EA\u5B9A\u4E49\u7C7B\u578B\xA0\xA0\u3010\u81EA\u5B9A\u4E49\u8D44\u6E90\u7C7B\u578B\u8868\u793A\u8BE5\u8D44\u6E90\u53EF\u9009\u62E9\u7684\u51E0\u79CD\u683C\u5F0F\u3011'
                            ),
                            React.createElement(
                                'div',
                                { style: {
                                        background: '#FFFFFF',
                                        paddingTop: '10px',
                                        paddingLeft: '10px',
                                        paddingRight: '10px'
                                    } },
                                React.createElement(
                                    Button,
                                    { size: 'xs',
                                        onClick: function onClick() {
                                            return _this8.addCustomType('CUSTOM_TYPE', function (ids) {
                                                _this8.setState({
                                                    customContentIds: ids
                                                });
                                            });
                                        } },
                                    '\u7C7B\u578B\u5217\u8868'
                                ),
                                React.createElement('hr', { style: { background: '#00acd6' } }),
                                React.createElement(
                                    'div',
                                    { id: 'customTypePerms',
                                        className: 'layui-input-block',
                                        style: { padding: '10px' } },
                                    this.state.customContentIds.map(function (array, index) {
                                        return React.createElement(
                                            'div',
                                            null,
                                            React.createElement(
                                                'div',
                                                { style: { float: 'left', marginRight: '20px' } },
                                                React.createElement(
                                                    'div',
                                                    null,
                                                    '\u81EA\u5B9A\u4E49\u5206\u7C7B\u540D\u79F0\uFF1A ',
                                                    array.custom_type_name
                                                )
                                            ),
                                            React.createElement(
                                                Button,
                                                { size: 'xs', btnType: 'danger',
                                                    onClick: function onClick() {
                                                        _this8.state.customContentIds.splice(index, 1);
                                                        _this8.setState({});
                                                    } },
                                                '\u5220\u9664'
                                            ),
                                            React.createElement(
                                                Button,
                                                { size: 'xs',
                                                    onClick: function onClick() {
                                                        return _this8.edit(array);
                                                    } },
                                                '\u67E5\u770B'
                                            ),
                                            React.createElement('hr', null)
                                        );
                                    })
                                )
                            )
                        )
                    )
                ),
                React.createElement(TreeModal, { ref: 'treeModal', nodes: this.state.modalList, errorStr: '\u65E0\u4E0A\u7EA7\u83DC\u5355',
                    onSelected: function onSelected(string, data) {
                        _this8.setState({
                            selectParent: {
                                parent_name: data.type_name ? data.type_name : '',
                                parent_code: data.type_code ? data.type_code : ''
                            }
                        }, function () {
                            _this8.customView(_this8.state.selectParent.parent_code);
                        });
                    } }),
                React.createElement(CustomTypeListModal, { ref: 'CustomTypeListModal', customType: this.state.addCustomType.customType,
                    callback: function callback(ids) {
                        return _this8.state.addCustomType.callback(ids);
                    } })
            );
        }
    }]);

    return ResourceType;
}(React.Component);

ReactDOM.render(React.createElement(ResourceType, null), document.getElementById('root'));